I'm trying to put together a little dxl script to help me flatten out access rights in some old/unmaintained projects.
// Set Access Inherited (Recursive)
void setModuleInherited(Module cur_mod)
// Set the current module and all objects inside to inherited access
{
Object cur_obj
inherited(cur_mod)
for cur_obj in cur_mod do
{
inherited(cur_obj)
}
}
void setFolderInherited(Folder cur_fold)
{
Module found_mod
Folder sub_fold
string NameItem
Item cur_itm
string iType = ""
print name(cur_fold) "\n"
// Set the current folder object to Inherited Access
inherited(cur_fold)
for cur_itm in cur_fold do
// Check each item in the current folder for Sub-Folders
{
iType = type(cur_itm)
NameItem = fullName(cur_itm)
print NameItem ", " iType "\n"
if (iType == "Formal")
// If the item is a Module, set Access rights for it
{
found_mod = edit(NameItem,false)
if (found_mod != null)
{
setModuleInherited(found_mod)
save(found_mod)
close(found_mod,false)
}
}
if (iType == "Folder")
// If the item is a Folder, get its name and create a
// Folder object to recurse on
{
// If the folder is for the Change Proposal System,
// leave it alone. Otherwise, recurse
if (NameItem != "Change Proposal System")
{
sub_fold = folder(cur_itm)
if (sub_fold != null)
{
setFolderInherited(sub_fold)
}
}
}
}
}
Folder current_fold = current Folder
setFolderInherited(current_fold)
for cur_item in cur_fold do loop, and I'm not sure how that happens. dbinkis - Fri Dec 04 10:25:42 EST 2009 |
Re: Recursively setting Inherited module/object attributes |
Re: Recursively setting Inherited module/object attributes doors36677 - Fri Dec 04 11:11:10 EST 2009 I'm astonished that comments can affect DXL code. I don't know that I've ever encountered that before with other languages. |
Re: Recursively setting Inherited module/object attributes dbinkis - Fri Dec 04 13:54:58 EST 2009 A comment is anything which begins with '//'. A line which begins with empty spaces, followed by '//' is a (somewhat useless, but formally correct) statement, followed by a comment. This, plus the fact that if clauses do not require brackets around the following code blocks, explain your case.
if (false)
// foo
{print "foo"}
print "bar"
produces "foobar" in the output pane, as the if clause only affects the following code block, which is // foo However,
if (false)
// foo
{print "foo"}
print "bar"
only produces "bar", as the complete line is a comment, and is as such ignored. If you want to indent comments, I suggest the following style:
if (false)
{ // foo
print "foo"
} // foo
print "bar"
Repeating the code at the closing brackets becomes extremely handy when you end up with many nested if blocks. |
Re: Recursively setting Inherited module/object attributes Your object loop should be "for cur_obj in entire cur_mod do". DOORS v9.2.0.1 has a bug and you might run into trouble settign inherited a deleted object. You might want to set "Link" and "Descriptive" modules inherited as well. You might want to set sub "Project"s inherited as well. Its good practice if you code your function better. In this case check for null folder and check for CPS folder at the top of the function. For debugging, print the error if so, and if not print the name of the folder.
|